home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / pctchnqs / 1992 / number2 / l2.cpp < prev    next >
Text File  |  1992-03-21  |  1KB  |  57 lines

  1. /* VGA mode 13h functions for Game of Life.
  2.    Tested with Borland C++ 3.0. */
  3. #include <stdio.h>
  4. #include <conio.h>
  5. #include <dos.h>
  6.  
  7. #define TEXT_X_OFFSET   27
  8. #define SCREEN_WIDTH_IN_BYTES 320
  9.  
  10. /* Width & height in pixels of each cell. */
  11. extern unsigned int magnifier;
  12.  
  13. /* Mode 13h draw pixel function. Pixels are of width & height
  14.    specified by magnifier. */
  15. void draw_pixel(unsigned int x, unsigned int y, unsigned int color)
  16. {
  17. #define SCREEN_SEGMENT  0xA000
  18.    unsigned char far *screen_ptr;
  19.    int i, j;
  20.  
  21.    FP_SEG(screen_ptr) = SCREEN_SEGMENT;
  22.    FP_OFF(screen_ptr) =
  23.          y * magnifier * SCREEN_WIDTH_IN_BYTES + x * magnifier;
  24.    for (i=0; i<magnifier; i++) {
  25.       for (j=0; j<magnifier; j++) {
  26.          *(screen_ptr+j) = color;
  27.       }
  28.       screen_ptr += SCREEN_WIDTH_IN_BYTES;
  29.    }
  30. }
  31.  
  32. /* Mode 13h mode-set function. */
  33. void enter_display_mode()
  34. {
  35.    union REGS regset;
  36.  
  37.    regset.x.ax = 0x0013;
  38.    int86(0x10, ®set, ®set);
  39. }
  40.  
  41. /* Text mode mode-set function. */
  42. void exit_display_mode()
  43. {
  44.    union REGS regset;
  45.  
  46.    regset.x.ax = 0x0003;
  47.    int86(0x10, ®set, ®set);
  48. }
  49.  
  50. /* Text display function. Offsets text to non-graphics area of
  51.    screen. */
  52. void show_text(int x, int y, char *text)
  53. {
  54.    gotoxy(TEXT_X_OFFSET + x, y);
  55.    puts(text);
  56. }
  57.